namespace :build do
  task :music => :environment do
    require 'find'
    require 'active_record'
    ActiveRecord::Base.establish_connection
  
    puts "Deleting all old songs..."
    Song.delete_all
    
    music_dir = '/Users/michaelboutros/Music/iTunes/iTunes Music'
    files = []
    
    Find.find(music_dir) do |file|
      if file.match(/.mp3$/)
        data = ID3Lib::Tag.new(file)
        puts "Processing song: " + data.title + "\n"
      
        Song.create(:title => data.title, :artist => data.artist, :album => data.album, :file => file)
      end
    end  
  end
end